package org.sixtynine.stock.dao.impl;

/**
 * @author Thilan
 *
 */

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.sixtynine.stock.dao.FilterDao;
import org.sixtynine.stock.dto.GridPramDTO;
import org.sixtynine.stock.dto.Page;
import org.sixtynine.stock.entity.Filter;
import org.springframework.stereotype.Repository;

@Repository
public class FilterDaoImpl extends AbstractDaoImpl<Filter, Integer> implements
		FilterDao {

	protected FilterDaoImpl() {
		super(Filter.class);
	}

	@Override
	public void saveFilter(Filter filter) {
		saveOrUpdate(filter);
	}

	@Override
	public List<Filter> findFilters(int filter) {
		return findByCriteria(Restrictions.eq("module.id", filter));
	}

	@Override
	public List<Filter> searchFilter(int categoryId) {
		Criteria criteria = getCurrentSession().createCriteria(Filter.class);
		if (categoryId != -1) {
			criteria.add(Restrictions.eq("filterCategory.id", categoryId));
		}
		return findByCriteria(criteria);
	}

	@Override
	public Page<Filter> searchFilter(int categoryId,
			GridPramDTO gridPramDTO) {
		Criteria criteria = getCurrentSession().createCriteria(
				Filter.class);
		if (categoryId != -1) {
			criteria.add(Restrictions.eq("filterCategory.id", categoryId));
		}
		
		return findByCriteria(criteria, gridPramDTO);
	}

}
